﻿using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.EntityLib.Cards.Character.Cirno;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;
using ProbeMod.StatusEffects;

namespace ProbeMod.Cards
{
    public sealed class ProbeUpgradeCompleteDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            CardConfig config = GetCardDefaultConfig();

            config.Rarity = Rarity.Common;
            config.Type = CardType.Ability;
            config.TargetType = TargetType.Nobody;

            config.Colors = new List<ManaColor>() { ManaColor.White };
            config.Cost = new ManaGroup() { White = 2, Any = 1 };
            config.UpgradedCost = new ManaGroup() { White = 2, Any = 1 };

            config.Value1 = 2;  // 火力灵力值
            config.Value2 = 3;  // 升级后火力灵力值

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 升级完毕
    /// 抉择：获得2火，下回合获得2灵；获得2灵，下回合获得2火
    /// </summary>
    [EntityLogic(typeof(ProbeUpgradeCompleteDef))]
    public sealed class ProbeUpgradeComplete : ProbeCard
    {
        public int Level => IsUpgraded ? Value2 : Value1;

        public override Interaction Precondition()
        {
            //  生成2个临时牌作为选项
            List<ProbeUpgradeComplete> list = Library.CreateCards<ProbeUpgradeComplete>(2, IsUpgraded).ToList();
            var cirnoConsider = list[0];
            var cirnoConsider2 = list[1];
            cirnoConsider.ChoiceCardIndicator = 1;
            cirnoConsider2.ChoiceCardIndicator = 2;
            cirnoConsider.SetBattle(base.Battle);
            cirnoConsider2.SetBattle(base.Battle);
            return new MiniSelectCardInteraction(list);
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            Card card = ((MiniSelectCardInteraction)precondition)?.SelectedCard;
            if (card != null)
            {
                if (card.ChoiceCardIndicator == 1)
                {
                    // 选项1
                    yield return BuffAction<Firepower>(level: Level);
                    yield return BuffAction<ProbeNextTurnSpiritSe>(level: Level);
                }
                else
                {
                    //  选项2
                    yield return BuffAction<Spirit>(level: Level);
                    yield return BuffAction<ProbeNextTurnPowerSe>(level: Level);
                }
            }
        }
    }
}
